﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Systems
{
    public class AudioFX
    {
        public string Name;
        public SoundEffect SFX;
        public AudioFX(string SoundName)
        {
            Name = SoundName;
        }
    }
    public class SoundManager
    {

        private static SoundManager theSoundManager;
        ContentManager theContent;

        List<AudioFX> SoundEffects;
        private SoundManager()
        {
            theContent = RoyalRumble.MainGame.theContent;
            SoundEffects = new List<AudioFX>();

            LoadSoundEffects();
        }

        public void LoadSoundEffects()
        {
            AudioFX MenuClick = new AudioFX("MenuClick");
            MenuClick.SFX = theContent.Load<SoundEffect>("Audio/MenuSelect");
            AudioFX MenuHover = new AudioFX("MenuHover");
            MenuHover.SFX = theContent.Load<SoundEffect>("Audio/MenuHover");

            AudioFX TankDriving = new AudioFX("TankDriving");
            TankDriving.SFX = theContent.Load<SoundEffect>("Audio/TankDriving");
            
            AudioFX GunFire1 = new AudioFX("GunFire1");
            GunFire1.SFX = theContent.Load<SoundEffect>("Audio/GunFire1");
            AudioFX GunFire2 = new AudioFX("GunFire2");
            GunFire1.SFX = theContent.Load<SoundEffect>("Audio/GunFire2");
            AudioFX GunFire3 = new AudioFX("GunFire3");
            GunFire1.SFX = theContent.Load<SoundEffect>("Audio/GunFire3");

            AudioFX Explosion1 = new AudioFX("Explosion1");
            Explosion1.SFX = theContent.Load<SoundEffect>("Audio/Explosion1");
            AudioFX Explosion2 = new AudioFX("Explosion2");
            Explosion1.SFX = theContent.Load<SoundEffect>("Audio/Explosion1");
            AudioFX Explosion3 = new AudioFX("Explosion3");
            Explosion1.SFX = theContent.Load<SoundEffect>("Audio/Explosion1");

            SoundEffects.Add(MenuHover);
            SoundEffects.Add(MenuClick);
            SoundEffects.Add(TankDriving);

            SoundEffects.Add(GunFire1);
            SoundEffects.Add(GunFire2);
            SoundEffects.Add(GunFire3);

            SoundEffects.Add(Explosion1);
            SoundEffects.Add(Explosion2);
            SoundEffects.Add(Explosion3);
        }

        public static SoundManager Instance
        {
            get
            {
                if (theSoundManager == null)
                    theSoundManager = new SoundManager();
                return theSoundManager;
            }
        }

        public void PlaySound(string SoundName)
        {
            for (int i = 0; i < SoundEffects.Count; i++)
            {
                if (SoundEffects[i].Name == SoundName)
                {
                    SoundEffects[i].SFX.Play();
                }
            }
        }
    }
}